﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Mesuro.Common {
	public class SeriesFilter : AbstractSeriesTransform {
		private Predicate<Vector> _predicate;

		public Predicate<Vector> Predicate {
			get { return _predicate; }
			set {
				_predicate = value;
				RaiseDataChanged( new NotifySeriesChangedEventArgs( this, NotifySeriesChangedAction.DataReplaced ) );
			}
		}

		public SeriesFilter() { }

		public SeriesFilter( Predicate<Vector> predicate ) {
			this.Predicate = predicate;
		}

		public override IEnumerator<Vector> GetEnumerator() {
			if (Source != null) {
				IEnumerator<Vector> enumr = Source.GetEnumerator();
				while (enumr.MoveNext())
					if (Predicate( enumr.Current ))
						yield return enumr.Current;
			}
		}
	}
}
